<?php
if (!isset($_SESSION['consultorio'])){
session_start();
}
//error_reporting(E_ALL ^ E_NOTICE);
error_reporting(0);
//display_errors();
//echo "pase";
require_once 'jq-configin.php';
// include the jqGrid Class

require_once ABSPATH."php/jqGrid.php";
// include the driver class
require_once ABSPATH."php/jqGridPdo.php";
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");


// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query

// Write the SQL Query

$grid->SelectCommand = "SELECT camas.idCama,sectorconsultorio.descSectorConsultorio,camas.Estado,camas.NumeroCama 
FROM camas INNER JOIN sectorconsultorio  
ON sectorconsultorio.idConsultorio='".$_SESSION['consultorio']."' AND 
sectorconsultorio.idSectorConsultorio=camas.idSectorConsultorio AND camas.Estado='Habilitada'";

/*
$grid->SelectCommand = "SELECT camas.idCama,sectorconsultorio.descSectorConsultorio, 
camas.Estado,camas.NumeroCama FROM camas, sectorconsultorio WHERE SectorConsultorio.idConsultorio='".$_SESSION['consultorio']."'" ;
*/
$grid->table = 'camas'; 
//echo $grid->SelectCommand ;
// Set the table to where you update the data
//$grid->table = 'paciente';
// Set output format to json
$grid->dataType = 'json';
// Let the grid create the model

$grid->setColModel();

$grid->setUrl("Internacion/Grid/gridcamainternacion.php");

// Set the url from where we obtain the data
// Set the url from where we obtain the data
// Set some grid options
$grid->setGridOptions(array(
        "caption"=>"Camas", 
        "width"=>420,
        "height"=>70,  
    "rowNum"=>20,
    "rowList"=>array(20,40,60),
    "shrinkToFit"=>false,
    "sortname"=>"idCama"
));

// Set the table to where you add the data 

$grid->setColProperty('idCama', array("label"=>"ID", "width"=>50));
$grid->setColProperty('descSectorConsultorio', array("label"=>"Sector", "width"=>200));
$grid->setColProperty('Estado', array("label"=>"Estado", "width"=>100));
$grid->setColProperty('NumeroCama', array("label"=>"Cama", "width"=>50));


$grid->toolbarfilter = true; 
// Enable navigator
$custom2 = <<<HC1
jQuery("#getCama1").click(function(){
    var selr1 = jQuery('#gridcamas').jqGrid('getGridParam','selrow');
    
    if(selr1)     
    {  
       var selcama = jQuery('#gridcamas').jqGrid('getRowData',selr1)
        
          $( "#idNumCama" ).show('200'); 
         //  document.getElementById("idNumCama").innerHTML=selcama.NumeroCama; 
           document.nameFormIngresoInternacion.nameNumCama.value = selcama.NumeroCama;
           document.nameFormIngresoInternacion.nameNumCama.name = Selcama.NumeroCama;
    }
    
	if(!selr1) alert("No selected row");
   return false;
    
});
HC1;
$grid->setJSCode($custom2); 

//$grid->setGridEvent('onSelectRow', $custom2);

$grid->navigator = true;
// Enable only editing
//$grid->setNavOptions('navigator', array("excel"=>false,"add"=>false,"edit"=>false,"del"=>false,"view"=>false));

$grid->setNavOptions('navigator', array("excel"=>true,"add"=>false,"edit"=>false,"del"=>false,"view"=>true, "search"=>true));

// Enjoy
$grid->renderGrid('#gridcamas','#pagercamas',true, null, null, true,true);
// we set the select for ship city 

//$grid->setSelect("ShipCity", "SELECT DISTINCT ShipCity, ShipCity AS CityName FROM orders ORDER BY 2", false, false, true, array(""=>"All"))

$conn = null;

?> 
 


